<?php
namespace kernel\library;

class Response
{
    //状态码
    public static $responseCode = 0;
    public static $responseData = [];
    /**
     * 返回json响应
     * @param array $data
     * @param number $status
     * @param array $headers
     * @param number $options
     */
    public static function json($data = [], $status = 200, array $headers = [], $cookie = []){
        $headers['Content-Type'] = 'application/json;charset=utf-8';
        $headers['Server'] = 'xyan/1.0';
        return [
            'status' => $status,
            'headers' => $headers,
            'cookies' => $cookie,
            'body' => json_encode($data, JSON_UNESCAPED_UNICODE),
        ];
    }
    
    /**
     * 返回响应
     * @param string $data
     * @param number $status
     * @param array $headers
     * @param number $options
     */
    public static function string($data, $status = 200, array $headers = [], $cookie = []){
        $headers['Server'] = 'xyan/1.0';
        return [
            'status' => $status,
            'headers' => $headers,
            'cookies' => $cookie,
            'body' => $data,
        ];
    }
    
    /**
     * 设置header信息
     * @param number $code
     * @param array $headers
     */
    private static function setHeader($code = 200, array $headers = []){
        http_response_code($code);
        foreach($headers as $k => $v){
            header($k.': '.$v);
        }
    }
    
}

